package com.tian.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tian.mapper.AdvisoryMapper;
import com.tian.mapper.DoctorMapper;
import com.tian.pojo.Advisory;
import com.tian.pojo.Doctor;
import com.tian.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

    @Service
    public class AdvisoryServiceImpl implements AdvisoryService{

        @Autowired
        private AdvisoryMapper advisoryMapper;



//        @Override
//        public List<Doctor> findAll() {
//            return doctorMapper.selectList(null);
//        }
//
        @Override
        public PageResult getDoctorList(PageResult pageResult) {
            //1.定义分页对象
            IPage page = new Page(pageResult.getPageNum(),pageResult.getPageSize());
            //构建查询的条件构造器
            QueryWrapper<Advisory> queryWrapper = new QueryWrapper<>();
            //根据判断条件决定是否拼接where条件
            queryWrapper.like(StringUtils.hasLength(pageResult.getQuery()),"name", pageResult.getQuery());
            //MP提供的分页查询方法,返回值是Page分页对象 其中包含分页的数据结果信息
            page = advisoryMapper.selectPage(page,queryWrapper);
            long total = page.getTotal();
            List records = page.getRecords();
            return pageResult.setRows(records).setTotal(total);
        }
//
//        @Override
//        public Doctor getById(Integer id) {
//            return doctorMapper.selectById(id);
//        }
//
//        @Override
//        public void updateDoctor(Doctor doctor) {
//            doctorMapper.updateById(doctor);
//        }
//
//        @Override
//        public void saveDoctor(Doctor doctor) {
//            doctor.setLevel(3);
//            doctorMapper.insert(doctor);
//        }
//
//        @Override
//        public void deleteUserById(Integer id) {
//            doctorMapper.deleteById(id);
//        }
//
//        @Override
//        public void putDoctorList(Doctor doctor) {
//            doctorMapper.updateById(doctor);
//        }
    }
